﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using DAO;

namespace Banking.Nhân_viên
{
    public partial class DangKyKhachHangCaNhan : UserControl
    {
        KhachHang khDTO;
        public DangKyKhachHangCaNhan(KhachHang kh)
        {
            InitializeComponent();
            khDTO = kh;
        }

        private void DangKyKhachHangCaNhan_Load(object sender, EventArgs e)
        {
            if (khDTO != null)
            {
                cmbChiNhanh.Text = khDTO.TruSo.Ten;
                txtMaKH.Text = khDTO.MaKH.ToString();
                txtHoTen.Text = khDTO.Ten;
                dtNgaySinh.Value = khDTO.NgaySinh;
                txtCMND.Text = khDTO.CMND.ToString();
                txtPassPost.Text = khDTO.PassPost;
                txtDiaChi.Text = khDTO.DiaChi;
                txtDienThoai.Text = khDTO.SoDT;
                cmbChiNhanh.Enabled = false;
                pnMain.Text = "Thông Tin Cá Nhân";
            }
            else
            {
                DataTable dt = NhanVienDAO.DSTruSo();
                cmbChiNhanh.DataSource = dt;
                cmbChiNhanh.DisplayMember = "Ten";
                cmbChiNhanh.ValueMember = "MaTruSo";
            }
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (txtHoTen.Text == "" || txtCMND.Text == "")
                return;
            khDTO = new KhachHang();
            khDTO.Ten = txtHoTen.Text;
            khDTO.CMND = int.Parse(txtCMND.Text);
            khDTO.PassPost = txtPassPost.Text;
            khDTO.NgaySinh = Convert.ToDateTime(dtNgaySinh.Value);
            khDTO.DiaChi = txtDiaChi.Text;
            khDTO.MaLoaiKH = 1;
            khDTO.SoDT = txtDienThoai.Text;
            khDTO.MaTruSo = Convert.ToInt32(cmbChiNhanh.SelectedValue);
            KhachHangDA.Update(khDTO);
        }

        private void ClearForm()
        {
            cmbChiNhanh.SelectedIndex = -1;
            txtCMND.Clear();
            txtDiaChi.Clear();
            txtDienThoai.Clear();
            txtHoTen.Clear();
            txtMaKH.Clear();
            txtMaTKC.Clear();
            txtPassPost.Clear();
            //dtNgaySinh.Value = "";
        }
    }
}
